package com.fxsh168.server.activity;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;

import com.fxsh168.server.R;


public class KehuPopupWindow extends PopupWindow {


	private Button btnKefu, btn_cancelKefu;
	private View mMenuViewKefu;
	private String callPhoneCur;

	public KehuPopupWindow(Activity context, OnClickListener itemsOnClick, String callPhoneCur) {
		super(context);
		this.callPhoneCur=callPhoneCur;
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mMenuViewKefu = inflater.inflate(R.layout.alert_dialog_kefuphone, null);
		btnKefu = (Button) mMenuViewKefu.findViewById(R.id.btnKefu);
		if (!TextUtils.isEmpty(callPhoneCur)) {
			btnKefu.setText(callPhoneCur);
			Log.e("callPhoneCur","callPhoneCurKehuPopupWindow="+callPhoneCur);
		}
		btn_cancelKefu = (Button) mMenuViewKefu.findViewById(R.id.btn_cancelKefu);
		//取消按钮
		btn_cancelKefu.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				//销毁弹出框
				dismiss();
			}
		});
		//设置按钮监听
		btnKefu.setOnClickListener(itemsOnClick);
		//设置SelectPicPopupWindow的View
		this.setContentView(mMenuViewKefu);
		//设置SelectPicPopupWindow弹出窗体的宽
		this.setWidth(LayoutParams.FILL_PARENT);
		//设置SelectPicPopupWindow弹出窗体的高
		this.setHeight(LayoutParams.WRAP_CONTENT);
		//设置SelectPicPopupWindow弹出窗体可点击
		this.setFocusable(true);
		//设置SelectPicPopupWindow弹出窗体动画效果
		this.setAnimationStyle(R.style.AnimBottom);
		//实例化一个ColorDrawable颜色为半透明
		ColorDrawable dw = new ColorDrawable(0xb0000000);
		//设置SelectPicPopupWindow弹出窗体的背景
		this.setBackgroundDrawable(dw);
		//mMenuView添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
		mMenuViewKefu.setOnTouchListener(new OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				int height = mMenuViewKefu.findViewById(R.id.pop_layoutKefu).getTop();
				int y=(int) event.getY();
				if(event.getAction()==MotionEvent.ACTION_UP){
					if(y<height){
						dismiss();
					}
				}				
				return true;
			}
		});

	}

}
